home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.2 Applications 1996 May / SGI IRIX 6.2 Applications 1996 May.iso / dist / impr_dev.idb / usr / impressario / src / examples / libspool / remove.c.z / remove.c
C/C++ Source or Header  |  1996-05-06  |  3KB  |  141 lines

  1. /**************************************************************************
  2.  *                                      *
  3.  *           Copyright (c)    1991 Silicon Graphics, Inc.          *
  4.  *            All Rights Reserved                    *
  5.  *                                      *
  6.  *       THIS    IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI          *
  7.  *                                      *
  8.  * The copyright notice above does not evidence any actual of intended      *
  9.  * publication of such source code, and is an unpublished work by Silicon *
  10.  * Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is *
  11.  * the property of Silicon Graphics, Inc. Any use, duplication or      *
  12.  * disclosure not specifically authorized by Silicon Graphics is strictly *
  13.  * prohibited.                                  *
  14.  *                                      *
  15.  * RESTRICTED RIGHTS LEGEND:                          *
  16.  *                                      *
  17.  * Use, duplication or disclosure by the Government is subject to      *
  18.  * restrictions as set forth in subdivision (c)(1)(ii) of the Rights in      *
  19.  * Technical Data and Computer Software clause at DFARS 52.227-7013,      *
  20.  * and/or in similar or successor clauses in the FAR, DOD or NASA FAR      *
  21.  * Supplement. Unpublished - rights reserved under the Copyright Laws of  *
  22.  * the United States. Contractor is SILICON GRAPHICS, INC., 2011 N.      *
  23.  * Shoreline Blvd., Mountain View, CA 94039-7311              *
  24.  **************************************************************************
  25.  *
  26.  * File: remove.c
  27.  *
  28.  * Description: Attempts to remove the specified job(s) from the specified
  29.  *    printer queue.
  30.  *
  31.  **************************************************************************/
  32.  
  33.  
  34. #ident "$Revision: 1.1 $"
  35.  
  36.  
  37. #include <stdio.h>
  38. #include <stdlib.h>
  39. #include <string.h>
  40. #ifdef sgi
  41. #include <getopt.h>
  42. #endif
  43. #include "spool.h"
  44.  
  45.  
  46. char *printer;
  47. char *job_id;
  48. int spooler = SL_SPOOLER_NONE;
  49.  
  50.  
  51. extern char *optarg;
  52. extern int optind;
  53.  
  54.  
  55. void usage(char*);
  56.  
  57.  
  58. main(int argc, char *argv[])
  59. {
  60.     int ch;
  61.     int errflag = 0;
  62.     register int i;
  63.  
  64.     /*
  65.      * Process command line args
  66.      */
  67.     while ((ch = getopt(argc, argv, "d:s:")) != -1) {
  68.     switch(ch) {
  69.         case 'd':        /* Destination printer */
  70.         printer = optarg;
  71.         break;
  72.         case 's':        /* Spooler to use */
  73.         if (!strcmp(optarg, "bsd"))
  74.             spooler = SL_SPOOLER_BSD;
  75.         else if (!strcmp(optarg, "sysv"))
  76.             spooler = SL_SPOOLER_SYSV;
  77.         else
  78.             errflag++;
  79.         break;
  80.         case '?':
  81.         default:
  82.         errflag++;
  83.         break;
  84.     }
  85.     }
  86.  
  87.     /*
  88.      * Get the job_id(s)
  89.      */
  90.     if (argc == optind)
  91.     errflag++;
  92.     else {
  93.     for (i = optind; i < argc; i++) {
  94.         int len = strlen(argv[i]);
  95.         if (job_id)
  96.         job_id = (char*)realloc(job_id, strlen(job_id)+len+5);
  97.         else {
  98.         job_id = (char*)malloc(len + 5);
  99.         *job_id = '\0';
  100.         }
  101.         (void)strcat(job_id, argv[i]);
  102.         (void)strcat(job_id, " ");
  103.     }
  104.     }
  105.  
  106.     /*
  107.      * If error print usage and exit
  108.      */
  109.     if (errflag) {
  110.     usage(argv[0]);
  111.     exit(1);
  112.     }
  113.  
  114.     /*
  115.      * Cancel the job
  116.      */
  117.     if (SLCancelJob(job_id, spooler, printer) < 0) {
  118.     int j, status, nout;
  119.     char **out_buf;
  120.     SLPerror(argv[0]);
  121.     if ((status = SLGetSpoolerError(&out_buf, &nout)) != 0) {
  122.         (void)fprintf(stderr, "Spooler exit status: %d\n", status);
  123.         (void)fprintf(stderr, "Spooler error message(s):\n");
  124.         for (j = 0; j < nout; j++)
  125.             (void)fprintf(stderr, "\t%s\n", out_buf[j]);
  126.     }
  127.     exit(1);
  128.     }
  129.  
  130.     (void)printf("Job cancel request sent\n");
  131.  
  132.     return 0;
  133. }
  134.  
  135.  
  136. void usage(char *progname)
  137. {
  138.     (void)fprintf(stderr, "%s [-d printer] [-s bsd | sysv] job_id(s)\n",
  139.                                 progname);
  140. }
  141.